package org.ielse.frame.test;

import android.os.Bundle;
import android.view.View;

import com.android.volley.VolleyError;

import org.ielse.frame.BaseActivity;
import org.ielse.frame.R;
import org.ielse.frame.view.SwitchView;

public class MainActivity extends BaseActivity {

	private SwitchView viewSwitch1, viewSwitch3;

	@Override protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		viewSwitch1 = (SwitchView) findViewById(R.id.view_switch1);
		viewSwitch1.setState(true);

		viewSwitch3 = (SwitchView) findViewById(R.id.view_switch3);
		viewSwitch3.setState(false);
		viewSwitch3.setOnStateChangedListener(new SwitchView.OnStateChangedListener() {
			@Override public void toggleToOn() {
				viewSwitch3.postDelayed(new Runnable() {
					@Override public void run() {
						viewSwitch3.toggleSwitch(true);
					}
				}, 300);
			}

			@Override public void toggleToOff() {
				viewSwitch3.postDelayed(new Runnable() {
					@Override public void run() {
						viewSwitch3.toggleSwitch(false);
					}
				}, 300);
			}

		});

		findViewById(R.id.btn_request_http).setOnClickListener(new View.OnClickListener() {
			@Override public void onClick(View v) {
				post("http://m.weather.com.cn/data/101010100.html", null, Weather.class, new VolleyListener<Weather>() {
					@Override public void onResponse(Weather response) {
						super.onResponse(response);
						showToast(response.toString());
					}

					@Override public void onErrorResponse(VolleyError error) {
						super.onErrorResponse(error);
						showToast(error.getMessage());
					}
				});
			}
		});

		findViewById(R.id.btn_start_activity_b).setOnClickListener(new View.OnClickListener() {
			@Override public void onClick(View arg0) {
				startActivity(NormalActivity.class);
			}
		});
	}

	public class Weather {

		private WeatherInfo weatherinfo;

		public WeatherInfo getWeatherinfo() {
			return weatherinfo;
		}

		public void setWeatherinfo(WeatherInfo weatherinfo) {
			this.weatherinfo = weatherinfo;
		}

		@Override public String toString() {
			return "Weather [weatherinfo=" + weatherinfo + "]";
		}

	}

	public class WeatherInfo {

		private String city;

		private String temp;

		private String time;

		public String getCity() {
			return city;
		}

		public void setCity(String city) {
			this.city = city;
		}

		public String getTemp() {
			return temp;
		}

		public void setTemp(String temp) {
			this.temp = temp;
		}

		public String getTime() {
			return time;
		}

		public void setTime(String time) {
			this.time = time;
		}

		@Override public String toString() {
			return "WeatherInfo [city=" + city + ", temp=" + temp + ", time=" + time + "]";
		}

	}

}
